import './App.css';
import Header from './components/Header'
import LoginPage from './components/LoginPage';
import ChatPageInterface from './components/ChatPage';
import { useState, useEffect } from 'react';
import axios from 'axios';
import { useNavigate, useLocation, Navigate, Route, Routes } from "react-router-dom";
import SideMenu from './components/SideMenu';

const isAuthenticated = () => {
  console.log(localStorage.getItem('accessToken') != null)
  return localStorage.getItem('accessToken') !== null;
};


function App() {
  let navigate = useNavigate();
  let location = useLocation();
  const [show, setShow] = useState(true)
  let from = location.state?.from?.pathname || "/chat";

  return (
    <div className="App">
      {isAuthenticated() && <Header></Header>}
      {isAuthenticated() && <SideMenu></SideMenu>}
      <Routes>
        <Route path="/login" element={<LoginPage />} />
        <Route path="/chat"
          element={isAuthenticated() ? (
            <ChatPageInterface setShow={setShow} />
          ) : (
            <Navigate to="/login" />
          )}
        />
      </Routes>
      {/* <LoginForm></LoginForm> */}

    </div>
  );
}

export default App;

